package com.imooc.mail.controller;

import com.github.pagehelper.PageInfo;
import com.imooc.mail.service.IProductService;
import com.imooc.mail.vo.ProductDetailVo;
import com.imooc.mail.vo.ProductVo;
import com.imooc.mail.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wjc
 * Date on 2020/6/7 10:56
 */
@RestController
@RequestMapping("/products")
public class ProductController {

    @Autowired
    private IProductService productService;

    @GetMapping
    public ResponseVo<PageInfo<ProductVo>> list(@RequestParam(required = false) Integer categoryId,
                                                @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                @RequestParam(required = false, defaultValue = "10") Integer pageSize){
        return productService.list(categoryId, pageNum, pageSize);

    }

    @GetMapping("/{productId}")
    public ResponseVo<ProductDetailVo> detail(@PathVariable Integer productId){
        return productService.detail(productId);
    }

}
